import 'package:flutter/material.dart';
import 'package:flutter_one/class/appsetting/setting.dart';

/*工具类*/
class Utils {
  //MARK: - 单例
  Utils._privateConstructor();

  static final Utils _request = Utils._privateConstructor();

  static Utils get shareInstance => _request;

  //MARK: - 自定义页面标题
  /// - 自定义页面标题
  Text customPageTitle(String title) {
    return Text(title,
        style: TextStyle(
          fontSize: 18,
          fontWeight: FontWeight.bold,
          color: hexToInt(0x333333),
        ),
        textAlign: TextAlign.center);
  }

  /// - 自定义AppBar
  AppBar customPageBar(String title) {
    return AppBar(
      //elevation: 4,
      title: customPageTitle(title),
      backgroundColor: K_APP_NAVIGATION_BACKGROUND_COLOR,
    );
  }

  //MARK: - 颜色转换
  /// - 颜色转换
  /// - @params hex:十六进制 0xffffff
  /// - @params alpha:0-1，透明到不透明
  /// - @returns Color
  Color hexToInt(int hex, {double alpha = 1}) {
    return Color.fromARGB(int.tryParse("${alpha * 255}") ?? 255,
            (hex & 0xFF0000) >> 16, (hex & 0xFF00) >> 8, (hex & 0xFF)) ??
        Colors.white;
  }
}
